﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrokerBase.Lib.Policy;
using BrokerBase.Lib.Product;

namespace broker.duty.JHRS
{
    class Class1
    {
        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.Period % 2 == 0 && ppa.Age<60)
            {
                da.Value = ppa.Amount * 0.08;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if ( ppa.Age >= 60 && ppa.Age<88)
            {
                da.Value = ppa.Amount * 0.15;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.Age == 88)
            {
                da.Value = ppa.Amount ;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.Period > 0 && ppa.SchemePeriodActing.InsurantStates.Contains("身故"))
            {
                if (ppa.Age < 18)
                {
                    da.Value = ppa.TotalFee;
                }
                else 
                {
                    double f1 = ppa.Amount;
                    double p1 = ppa.GetDutyTotalValue("生存金给付") + ppa.GetDutyTotalValue("养老金给付");
                    double f2 = ppa.TotalFee - p1 > 0 ? ppa.TotalFee - p1 : 0;

                    da.Value = f1 > f2 ? f1 : f2;
                    da.Description = "如果现金价值较大，则支付现金价值";
                }

                ppa.IsCurrentFinish = true;
            }        
        }


        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.Period > 0)
            {
                double f = (double)ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("分红率(预估)");

                da.Value = ppa.TotalFee * f;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.IsLastPeriod)
            {
                da.Value = ppa.Amount * 3;
                ppa.IsCurrentFinish = true;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("疾病身故"))
            {
                if (ppa.Period == 0)
                {
                    da.Value = ppa.TotalFee;
                }
                ppa.SchemePeriodActing.InsurantStates.Add("身故");
                ppa.IsCurrentFinish = true;
            }
            else if (ppa.SchemePeriodActing.InsurantStates.Contains("意外身故"))
            {
                ppa.SchemePeriodActing.InsurantStates.Add("身故");
                da.Value = ppa.Amount * 3;
                ppa.IsCurrentFinish = true;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("身故"))
            {
                if (ppa.PolicyActing.Policy.SelectedPaymentPeriod.Style == PaymentPeriodStyle.Once)
                {
                    da.Value = ppa.Amount;
                }
                else if (ppa.IsAtPaymentPeriod)
                {
                    da.Value = ppa.Amount * (1 + 0.05 * (ppa.Period));
                }
                else
                {
                    da.Value = ppa.Amount * (1 + 0.05 * (ppa.PolicyActing.Policy.PaymentPeriodLength));
                }
                ppa.IsCurrentFinish = true;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.Age ==22 )
            {
                da.Value = ppa.Amount;
                ppa.IsCurrentFinish = true;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("重疾"))
            {
                switch (ppa.Age)
                {
                    case 0:
                        da.Value = ppa.Amount * 0.3;
                        break;
                    case 1:
                        da.Value = ppa.Amount * 0.6;
                        break;
                    default:
                        da.Value = ppa.Amount;
                        break;
                }
                ppa.IsCurrentFinish = true;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("全残"))
            {
                da.Value = ppa.Amount;
                if (ppa.Period > 0)
                    ppa.Fee = 0;
            }
        }
    }
}
